home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Text / WASTE / WASTE 1.1.2 Distribution / Pseudo-UPI for THINK Pascal / TextServices.p < prev    next >
Encoding:
Text File  |  1995-10-12  |  12.5 KB  |  345 lines  |  [TEXT/PJMM]

  1. unit TextServices;
  2.  
  3. { Pascal Interface to the Macintosh Libraries }
  4.  
  5. { Copyright © Apple Computer Inc. }
  6. { All Rights Reserved }
  7.  
  8. { Adapted for use with THINK Pascal 4.0.x by Marco Piovanelli }
  9.  
  10. interface
  11.     uses
  12.         AppleEvents, Components;
  13.  
  14.     const
  15.  
  16. { TSM gestalt constants (!!! transplanted from GestaltEqu.p !!!) }
  17.  
  18.         gestaltTSMgrVersion = 'tsmv';
  19.  
  20.         gestaltTSMgrAttr = 'tsma';                        { Text Services Mgr attributes, if present }
  21.         gestaltTSMDisplayMgrAwareBit = 0;                            { TSM knows about display manager }
  22.  
  23. { TSM errors (!!! transplanted from Errors.p !!!) }
  24.  
  25.         tsmComponentNoErr = 0;                            { component result = no error }
  26.         tsmUnsupScriptLanguageErr = -2500;
  27.         tsmInputMethodNotFoundErr = -2501;
  28.         tsmNotAnAppErr = -2502;                        { not an application error }
  29.         tsmAlreadyRegisteredErr = -2503;                        { want to register again error }
  30.         tsmNeverRegisteredErr = -2504;                        { app never registered error (not TSM aware) }
  31.         tsmInvalidDocIDErr = -2505;                        { invalid TSM documentation id }
  32.         tsmTSMDocBusyErr = -2506;                        { document is still active }
  33.         tsmDocNotActiveErr = -2507;                        { document is NOT active }
  34.         tsmNoOpenTSErr = -2508;                        { no open text service }
  35.         tsmCantOpenComponentErr = -2509;                        { can’t open the component }
  36.         tsmTextServiceNotFoundErr = -2510;                        { no text service found }
  37.         tsmDocumentOpenErr = -2511;                        { there are open documents }
  38.         tsmUseInputWindowErr = -2512;                        { not TSM aware because we are using input window }
  39.         tsmTSHasNoMenuErr = -2513;                        { the text service has no menu }
  40.         tsmTSNotOpenErr = -2514;                        { text service is not open }
  41.         tsmComponentAlreadyOpenErr = -2515;                        { text service already opened for the document }
  42.         tsmInputMethodIsOldErr = -2516;                        { returned by GetDefaultInputMethod }
  43.         tsmScriptHasNoIMErr = -2517;                        { script has no imput method or is using old IM }
  44.         tsmUnsupportedTypeErr = -2518;                        { unSupported interface type error }
  45.         tsmUnknownErr = -2519;                        { any other errors }
  46.  
  47. { AppleEvent error definitions (!!! transplanted from Errors.p !!!) }
  48.         errOffsetInvalid = -1800;
  49.         errOffsetIsOutsideOfView = -1801;
  50.         errTopOfDocument = -1810;
  51.         errTopOfBody = -1811;
  52.         errEndOfDocument = -1812;
  53.         errEndOfBody = -1813;
  54.  
  55.  
  56.         kTSMVersion = $200;                            { Version of the Text Services Manager is 2.0  }
  57.         kTextService = 'tsvc';                        { component type for the component description }
  58.         kInputMethodService = 'inpm';                        { component subtype for the component description }
  59.  
  60. { Component Flags in ComponentDescription }
  61.         bTakeActiveEvent = 15;                            { bit set if the component takes active event }
  62.         bHandleAERecording = 16;                            { bit set if the component takes care of recording Apple Events <new in vers2.0> }
  63.         bScriptMask = $00007F00;                    { bit 8 - 14 }
  64.         bLanguageMask = $000000FF;                    { bit 0 - 7  }
  65.         bScriptLanguageMask = bScriptMask + bLanguageMask;    { bit 0 - 14  }
  66.  
  67. { Hilite styles }
  68.         kCaretPosition = 1;                            { specify caret position }
  69.         kRawText = 2;                            { specify range of raw text }
  70.         kSelectedRawText = 3;                            { specify range of selected raw text }
  71.         kConvertedText = 4;                            { specify range of converted text }
  72.         kSelectedConvertedText = 5;                            { specify range of selected converted text }
  73.  
  74. { Apple Event constants }
  75. { Event class }
  76.         kTextServiceClass = kTextService;
  77. { event ID }
  78.         kUpdateActiveInputArea = 'updt';                        { update the active Inline area }
  79.         kPos2Offset = 'p2st';                        { converting global coordinates to char position }
  80.         kOffset2Pos = 'st2p';                        { converting char position to global coordinates }
  81.         kShowHideInputWindow = 'shiw';                        { show or hide the input window }
  82. { Event keywords }
  83.         keyAETSMDocumentRefcon = 'refc';                        { TSM document refcon, typeLongInteger }
  84. { Note: keyAETSMScriptTag, keyAERequestedType, keyAETSMTextFont, keyAETextPointSize}
  85. {    typeAEText, typeIntlWritingCode, typeQDPoint, and keyAEAngle have been moved to }
  86. {    AERegistry.h }
  87.         keyAEServerInstance = 'srvi';                        { component instance }
  88.         keyAETheData = 'kdat';                        { typeText }
  89.         keyAEFixLength = 'fixl';                        { fix len ?? }
  90.         keyAEHiliteRange = 'hrng';                        { hilite range array }
  91.         keyAEUpdateRange = 'udng';                        { update range array }
  92.         keyAEClauseOffsets = 'clau';                        { Clause Offsets array }
  93.         keyAECurrentPoint = 'cpos';                        { current point }
  94.         keyAEDragging = 'bool';                        { dragging falg }
  95.         keyAEOffset = 'ofst';                        { offset }
  96.         keyAERegionClass = 'rgnc';                        { region class }
  97.         keyAEPoint = 'gpos';                        { current point }
  98.         keyAEBufferSize = 'buff';                        { buffer size to get the text }
  99.         keyAEMoveView = 'mvvw';                        { move view flag }
  100.         keyAELength = 'leng';                        { length }
  101.         keyAENextBody = 'nxbd';                        { next or previous body }
  102. { optional keywords for Offset2Pos (Info about the active input area) }
  103.         keyAETextLineHeight = 'ktlh';                        { typeShortInteger }
  104.         keyAETextLineAscent = 'ktas';                        { typeShortInteger }
  105. { optional keywords for Pos2Offset }
  106.         keyAELeftSide = 'klef';                        { type Boolean }
  107. { optional keywords for kShowHideInputWindow }
  108.         keyAEShowHideInputWindow = 'shiw';                        { type Boolean }
  109. { for PinRange  }
  110.         keyAEPinRange = 'pnrg';
  111. { Desc type ... }
  112.         typeComponentInstance = 'cmpi';                        { server instance }
  113.         typeTextRangeArray = 'tray';                        { text range array }
  114.         typeOffsetArray = 'ofay';                        { offset array }
  115.         typeText = 'TEXT';                        { Plain text }
  116.         typeTextRange = 'txrn';
  117.  
  118. { Desc type constants }
  119.         kTSMOutsideOfBody = 1;
  120.         kTSMInsideOfBody = 2;
  121.         kTSMInsideOfActiveInputArea = 3;
  122.  
  123.         kNextBody = 1;
  124.         kPreviousBody = 2;
  125.  
  126. { typeTextRange         'txrn' }
  127.  
  128.     type
  129.         TextRange = record
  130.                 fStart: LONGINT;
  131.                 fEnd: LONGINT;
  132.                 fHiliteStyle: INTEGER;
  133.             end;
  134.         TextRangePtr = ^TextRange;
  135.  
  136.         TextRangeHandle = ^TextRangePtr;
  137.  
  138. { typeTextRangeArray    'txra' }
  139.         TextRangeArray = record
  140.                 fNumOfRanges: INTEGER;                                { specify the size of the fRange array }
  141.                 fRange: array[0..0] of TextRange;                { when fNumOfRanges > 1, the size of this array has to be calculated }
  142.             end;
  143.         TextRangeArrayPtr = ^TextRangeArray;
  144.  
  145.         TextRangeArrayHandle = ^TextRangeArrayPtr;
  146.  
  147. { typeOffsetArray        'offa' }
  148.         OffsetArray = record
  149.                 fNumOfOffsets: INTEGER;                                { specify the size of the fOffset array }
  150.                 fOffset: array[0..0] of LONGINT;                { when fNumOfOffsets > 1, the size of this array has to be calculated }
  151.             end;
  152.         OffsetArrayPtr = ^OffsetArray;
  153.  
  154.         OffsetArrayHandle = ^OffsetArrayPtr;
  155.  
  156.         TSMDocumentID = Ptr;
  157.  
  158.         InterfaceTypeList = array[0..0] of OSType;
  159.  
  160. { Text Service Info List }
  161.         TextServiceInfo = record
  162.                 fComponent: Component;
  163.                 fItemName: Str255;
  164.             end;
  165.         TextServiceInfoPtr = ^TextServiceInfo;
  166.  
  167.         TextServiceList = record
  168.                 fTextServiceCount: INTEGER;                                { number of entries in the 'fServices' array }
  169.                 fServices: array[0..0] of TextServiceInfo;        { Note: array of 'TextServiceInfo' records follows }
  170.             end;
  171.         TextServiceListPtr = ^TextServiceList;
  172.  
  173.         TextServiceListHandle = ^TextServiceListPtr;
  174.  
  175.         ScriptLanguageRecord = record
  176.                 fScript: ScriptCode;
  177.                 fLanguage: LangCode;
  178.             end;
  179.         ScriptLanguageSupport = record
  180.                 fScriptLanguageCount: INTEGER;                                { number of entries in the 'fScriptLanguageArray' array }
  181.                 fScriptLanguageArray: array[0..0] of ScriptLanguageRecord;    { Note: array of 'ScriptLanguageRecord' records follows }
  182.             end;
  183.         ScriptLanguageSupportPtr = ^ScriptLanguageSupport;
  184.  
  185.         ScriptLanguageSupportHandle = ^ScriptLanguageSupportPtr;
  186.  
  187.  
  188.     const
  189. { Low level routines which are dispatched directly to the Component Manager }
  190.         kCMGetScriptLangSupport = $0001;                        { Component Manager call selector 1 }
  191.         kCMInitiateTextService = $0002;                        { Component Manager call selector 2 }
  192.         kCMTerminateTextService = $0003;                        { Component Manager call selector 3 }
  193.         kCMActivateTextService = $0004;                        { Component Manager call selector 4 }
  194.         kCMDeactivateTextService = $0005;                        { Component Manager call selector 5 }
  195.         kCMTextServiceEvent = $0006;                        { Component Manager call selector 6 }
  196.         kCMGetTextServiceMenu = $0007;                        { Component Manager call selector 7 }
  197.         kCMTextServiceMenuSelect = $0008;                        { Component Manager call selector 8 }
  198.         kCMFixTextService = $0009;                        { Component Manager call selector 9 }
  199.         kCMSetTextServiceCursor = $000A;                        { Component Manager call selector 10 }
  200.         kCMHidePaletteWindows = $000B;                        { Component Manager call selector 11 }
  201.  
  202. { High level TSM routines }
  203.  
  204.     function NewTSMDocument (numOfInterface: INTEGER;
  205.                                     var supportedInterfaceTypes: InterfaceTypeList;
  206.                                     var idocID: TSMDocumentID;
  207.                                     refcon: LONGINT): OSErr;
  208.     inline
  209.         $7000, $AA54;
  210.     function DeleteTSMDocument (idocID: TSMDocumentID): OSErr;
  211.     inline
  212.         $7001, $AA54;
  213.     function ActivateTSMDocument (idocID: TSMDocumentID): OSErr;
  214.     inline
  215.         $7002, $AA54;
  216.     function DeactivateTSMDocument (idocID: TSMDocumentID): OSErr;
  217.     inline
  218.         $7003, $AA54;
  219.     function TSMEvent (var event: EventRecord): BOOLEAN;
  220.     inline
  221.         $7004, $AA54;
  222.     function TSMMenuSelect (menuResult: LONGINT): BOOLEAN;
  223.     inline
  224.         $7005, $AA54;
  225.     function SetTSMCursor (mousePos: Point): BOOLEAN;
  226.     inline
  227.         $7006, $AA54;
  228.     function FixTSMDocument (idocID: TSMDocumentID): OSErr;
  229.     inline
  230.         $7007, $AA54;
  231.     function GetServiceList (numOfInterface: INTEGER;
  232.                                     var supportedInterfaceTypes: OSType;
  233.                                     var serviceInfo: TextServiceListHandle;
  234.                                     var seedValue: LONGINT): OSErr;
  235.     inline
  236.         $7008, $AA54;
  237.     function OpenTextService (idocID: TSMDocumentID;
  238.                                     aComponent: Component;
  239.                                     var aComponentInstance: ComponentInstance): OSErr;
  240.     inline
  241.         $7009, $AA54;
  242.     function CloseTextService (idocID: TSMDocumentID;
  243.                                     aComponentInstance: ComponentInstance): OSErr;
  244.     inline
  245.         $700A, $AA54;
  246.     function SendAEFromTSMComponent ({CONST}
  247.                                     var theAppleEvent: AppleEvent;
  248.                                     var reply: AppleEvent;
  249.                                     sendMode: AESendMode;
  250.                                     sendPriority: AESendPriority;
  251.                                     timeOutInTicks: LONGINT;
  252.                                     idleProc: AEIdleUPP;
  253.                                     filterProc: AEFilterUPP): OSErr;
  254.     inline
  255.         $700B, $AA54;
  256.     function InitTSMAwareApplication: OSErr;
  257.     inline
  258.         $7014, $AA54;
  259.     function CloseTSMAwareApplication: OSErr;
  260.     inline
  261.         $7015, $AA54;
  262. { Utilities }
  263.     function SetDefaultInputMethod (ts: Component;
  264.                                     var slRecordPtr: ScriptLanguageRecord): OSErr;
  265.     inline
  266.         $700C, $AA54;
  267.     function GetDefaultInputMethod (var ts: Component;
  268.                                     var slRecordPtr: ScriptLanguageRecord): OSErr;
  269.     inline
  270.         $700D, $AA54;
  271.     function SetTextServiceLanguage (var slRecordPtr: ScriptLanguageRecord): OSErr;
  272.     inline
  273.         $700E, $AA54;
  274.     function GetTextServiceLanguage (var slRecordPtr: ScriptLanguageRecord): OSErr;
  275.     inline
  276.         $700F, $AA54;
  277.     function UseInputWindow (idocID: TSMDocumentID;
  278.                                     useWindow: BOOLEAN): OSErr;
  279.     inline
  280.         $7010, $AA54;
  281.     function NewServiceWindow (wStorage: univ Ptr; {CONST}
  282.                                     var boundsRect: Rect;
  283.                                     title: ConstStr255Param;
  284.                                     visible: BOOLEAN;
  285.                                     theProc: INTEGER;
  286.                                     behind: WindowPtr;
  287.                                     goAwayFlag: BOOLEAN;
  288.                                     ts: ComponentInstance;
  289.                                     var window: WindowPtr): OSErr;
  290.     inline
  291.         $7011, $AA54;
  292.     function CloseServiceWindow (window: WindowPtr): OSErr;
  293.     inline
  294.         $7012, $AA54;
  295.     function GetFrontServiceWindow (var window: WindowPtr): OSErr;
  296.     inline
  297.         $7013, $AA54;
  298.     function FindServiceWindow (thePoint: Point;
  299.                                     var theWindow: WindowPtr): INTEGER;
  300.     inline
  301.         $7017, $AA54;
  302. { Low level TSM routines }
  303.     function GetScriptLanguageSupport (ts: ComponentInstance;
  304.                                     var scriptHdl: ScriptLanguageSupportHandle): ComponentResult;
  305.     inline
  306.         $2F3C, $04, $0001, $7000, $A82A;
  307.     function InitiateTextService (ts: ComponentInstance): ComponentResult;
  308.     inline
  309.         $2F3C, $00, $0002, $7000, $A82A;
  310.     function TerminateTextService (ts: ComponentInstance): ComponentResult;
  311.     inline
  312.         $2F3C, $00, $0003, $7000, $A82A;
  313.     function ActivateTextService (ts: ComponentInstance): ComponentResult;
  314.     inline
  315.         $2F3C, $00, $0004, $7000, $A82A;
  316.     function DeactivateTextService (ts: ComponentInstance): ComponentResult;
  317.     inline
  318.         $2F3C, $00, $0005, $7000, $A82A;
  319.     function TextServiceEvent (ts: ComponentInstance;
  320.                                     numOfEvents: INTEGER;
  321.                                     var event: EventRecord): ComponentResult;
  322.     inline
  323.         $2F3C, $06, $0006, $7000, $A82A;
  324.     function GetTextServiceMenu (ts: ComponentInstance;
  325.                                     var serviceMenu: MenuHandle): ComponentResult;
  326.     inline
  327.         $2F3C, $4, $0007, $7000, $A82A;
  328.     function TextServiceMenuSelect (ts: ComponentInstance;
  329.                                     serviceMenu: MenuHandle;
  330.                                     item: INTEGER): ComponentResult;
  331.     inline
  332.         $2F3C, $06, $0008, $7000, $A82A;
  333.     function FixTextService (ts: ComponentInstance): ComponentResult;
  334.     inline
  335.         $2F3C, $00, $0009, $7000, $A82A;
  336.     function SetTextServiceCursor (ts: ComponentInstance;
  337.                                     mousePos: Point): ComponentResult;
  338.     inline
  339.         $2F3C, $04, $000A, $7000, $A82A;
  340.     function HidePaletteWindows (ts: ComponentInstance): ComponentResult;
  341.     inline
  342.         $2F3C, $00, $000B, $7000, $A82A;
  343.  
  344. implementation
  345. end.